import { ArticleSummaryModel } from "../models/articleSummaryModel";

const get = (requestUrl: string, parm?: any): Promise<Response> => {
    let url = requestUrl;
    if (parm) {
        url = url + "?";
    }
    for (var item in parm) {
        url = `${url}${item}=${parm[item]}&`;
    }
    return fetch(url);
};

const post = (
    url: string,
    param: any,
    method: "POST" | "PUT" | "DELETE" = "POST",
    json: string = ""
): Promise<Response> => {
    return fetch(url, {
        method: method,
        body: param ? JSON.stringify(param) : json,
        headers: {
            "Content-Type": "application/json",
        },
    });
};

export const getHomeArticleList = (type: string): Promise<ArticleSummaryModel[]> => {
    return new Promise(r => r([{
        title: "title",
        summary: "summary",
        date: "2020-1-1",
        cover: "https://www.baidu.com/img/flexible/logo/pc/result.png"
    }]));
}
